#region using

using System;
using System.Web;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using BlogEngine.Core.Web.Controls;
using BlogEngine.Core;
using Controls;

#endregion

/// <summary>
/// Renders the appropriate code to display a photo via the Photo handler when a [photo] tag is found.
/// <example>
/// [slideshow:myalbum,400,400] will get the album with the slug "myalbum" and issue code for the slideshow</example>
/// </summary>
[Extension("Display a slideshow via the Photo handler", "0.1", "BlogEngine.NET")]
public class ShowSlideShow : RegexMatchBase
{
    private static readonly Regex _BodyRegex = new Regex(@"\[slideshow:([A-Za-z0-9_\-]*)(,\w*)*\]", RegexOptions.Compiled | RegexOptions.IgnoreCase);

    /// <summary>
    /// Hooks up an event handler to the Post.Serving and Page.Serving events.
    /// </summary>
    public ShowSlideShow()
        : base()
    {
        base.Regex = _BodyRegex;
    }

    /// <summary>
    /// Handles the Page and Post Serving event to take care of the [photo] keyword.
    /// </summary>
    protected override string MatchCore(Match match)
    {
        using (System.IO.StringWriter sw = new System.IO.StringWriter())
        {
            SlideShow slideshow = new SlideShow();
            slideshow.AlbumSlug = match.Groups[1].Value;
            slideshow.Width = 640;
            slideshow.Height = 480;
            slideshow.RenderControl(new HtmlTextWriter(sw));
            return sw.ToString();
        }
    }
}